package com.itheima.health.controller.backend;

import com.itheima.health.pojo.Member;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.health.entity.Result;

import javax.servlet.http.HttpSession;

@RestController
public class TestController {
    @RequestMapping("/hello")
    public Result hello(HttpSession session) {

        Member member=new Member();
        //把登录用户信息存入session
        session.setAttribute("loginUser",member);
        return new Result(true, "yyds");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            System.out.println("md5:" + DigestUtils.md5DigestAsHex("123456".getBytes()));
        }
        //密码加密器
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        for (int i = 0; i < 5; i++) {
            String encryptedPwd = encoder.encode("123456");
            System.out.println("encryptedPwd=" + encryptedPwd);
        }

    //校验密码是否正确
    //密文，明文
        System.out.println(encoder.matches("123456","$2a$10$3piVCEvljVcfgw6jjMkoIuNYeT/8CX8qJXMjfvToRVXjOhM7dYNga"));
        System.out.println(encoder.matches("123456","$2a$10$TTaVf6yljv0uiusvBhBYoOtWdZn21y/Uh/jsVkKA5/Jt4lwVT4Kdu"));
        System.out.println(encoder.matches("123456","$2a$10$jBoiUXXoNa4per5SBO39deNiNUDH7WQbqanZJShXdiZByOSEQFDBa"));
        System.out.println(encoder.matches("123456","$2a$10$BGg3.Y6EYCBie6T03TxiieGnSODbjC2wZN.A06OEj9Om17lMj75dy"));
        System.out.println(encoder.matches("123456","$2a$10$QoBMcosI72kQXNljrJsPn.MOj9eDrkHrECyESDnemmncvRU10g4dy"));

    }
}


